package com.ftx.manager.article.impl;

import com.ftx.common.enums.ArticleStatusEnum;
import com.ftx.common.util.CollectionUtils;
import com.ftx.dao.ArticleMapper;
import com.ftx.domain.alias.Article;
import com.ftx.domain.alias.PageCondition;
import com.ftx.domain.content.NumContent;
import com.ftx.domain.query.ArticleQuery;
import com.ftx.domain.vo.ArticleVO;
import com.ftx.domain.vo.PageVO;
import com.ftx.manager.article.ArticleManager;
import com.ibatis.common.util.PaginatedList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by fengtingxin on 2019/6/10.
 */
@Service
public class ArticleManagerImpl implements ArticleManager {

    @Resource
    private ArticleMapper articleMapper;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());



    @Override
    public List<ArticleVO> pageByCondition(PageCondition pageCondition, ArticleQuery query) {
        Article param = new Article();
        param.setArticleStatus(ArticleStatusEnum.RELEASE_COMPLETED.getKey());
        logger.info("pageByCondition is {}",pageCondition);
        List<Article> articles = articleMapper.pageByCondition(pageCondition,param);
        logger.info("pageByCondition is {}",pageCondition);

        if (CollectionUtils.isEmpty(articles)){
            return null;
        }
        List<ArticleVO> articleVOList = new ArrayList<>(20);
        for (Article article : articles){
            ArticleVO articleVO = new ArticleVO();
            BeanUtils.copyProperties(article,articleVO);
            articleVOList.add(articleVO);
        }
        return articleVOList;
    }
}
